package com.cskaoyan.market.service.impl;

import com.cskaoyan.market.db.domain.MarketFeedback;
import com.cskaoyan.market.db.domain.MarketFeedbackExample;
import com.cskaoyan.market.db.mapper.MarketFeedbackMapper;
import com.cskaoyan.market.service.AdminFeedbackService;
import com.github.pagehelper.PageHelper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class AdminFeedbackServiceImpl implements AdminFeedbackService {

    @Autowired
    MarketFeedbackMapper mapper;

    @Override
    @Transactional
    public List<MarketFeedback> list(Integer page, Integer limit, String username, Integer id, String sort, String order) {
        MarketFeedbackExample marketFeedbackExample = new MarketFeedbackExample();
        MarketFeedbackExample.Criteria criteria = marketFeedbackExample.createCriteria();
        if(!StringUtils.isEmpty(username))
            criteria.andUsernameEqualTo("%"+username+"%");
        if(id!=null)
            criteria.andIdEqualTo(id);
        marketFeedbackExample.setOrderByClause(sort + " " + order);
        PageHelper.startPage(page,limit);
        List<MarketFeedback> marketFeedbacks = mapper.selectByExample(marketFeedbackExample);
        return marketFeedbacks;
    }
}
